package com.web_bloks.widget.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Image;

/**
 * 
 * @author Jean-Lou Dupont
 *
 */
public class GearsStatus extends Anchor {

	Image img = null;
	
	public GearsStatus() {
		super();
		setup();
	}
	
	private void setup() {
		
		final WidgetMessages MSG = (WidgetMessages) GWT.create(WidgetMessages.class);
		
		WidgetImageBundle bundle = (WidgetImageBundle) GWT.create( WidgetImageBundle.class );
		
		AbstractImagePrototype p = null;
		
		if (isGearsInstalled()) {
			p = bundle.gears();
			this.setHref(MSG.gears_href_installed());
			this.setTitle(MSG.gears_title_installed());

		} else {
			p = bundle.gears_grey();
			this.setHref(MSG.gears_href_not_installed());
			this.setTitle(MSG.gears_title_not_installed());
		}
		
		img = p.createImage();	
		
		this.getElement().appendChild(img.getElement());
	}
	
	private static native boolean isGearsInstalled() /*-{
		try {
			return $wnd.google.gears.factory != null;
		} catch (e) {
			return false;
		}
	}-*/;

	
}//END